public class Solution {
    public TreeNode invertTree(TreeNode root) {
        if(root == null)
            return null;
        TreeNode left = invertTree(root.left);
        TreeNode right = invertTree(root.right);
        root.left = right;
        root.right = left;
        return root;
    }

    public static void main(String[] args) {
        // 创建一个简单的二叉树
        //      1
        //     / \
        //    2   3
        //   / \
        //  4   5
        TreeNode root = new TreeNode(1);
        root.left = new TreeNode(2);
        root.right = new TreeNode(3);
        root.left.left = new TreeNode(4);
        root.left.right = new TreeNode(5);

        Solution solution = new Solution();
        TreeNode invertedRoot = solution.invertTree(root);

        // 输出反转后的二叉树（这里只是简单地输出根节点的值和左右子节点的值）
        System.out.println("Root: " + invertedRoot.val);
        System.out.println("Left: " + (invertedRoot.left != null ? invertedRoot.left.val : "null"));
        System.out.println("Right: " + (invertedRoot.right != null ? invertedRoot.right.val : "null"));
    }
}
